package com.example.xymarket.myView;

import android.content.Context;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.Button;

import androidx.annotation.Nullable;

public class MyRoundButton extends androidx.appcompat.widget.AppCompatButton implements View.OnClickListener {

    float radius = 100f;//半径
    private int height;
    private int width;
    private String TAG = "test";
    private boolean open = false;

    public MyRoundButton(Context context) {
        this(context, null);
    }

    public MyRoundButton(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MyRoundButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        radius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radius, getResources().getDisplayMetrics());
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(50, heightMeasureSpec);
    }

    @Override
    public void layout(int l, int t, int r, int b) {
        int left = (int) (width / 2 - Math.cos(Math.toRadians( 45)) * radius - this.getMeasuredWidth() / 2);
        int top = (int) (height - Math.sin(Math.toRadians(45)) * radius - this.getMeasuredHeight());
        super.layout(left, top, left + this.getMeasuredHeight(), top + this.getMeasuredHeight());
    }

    @Override
    public void onClick(View v) {

    }
}
